package com.fh.shop.admin.book.biz;

import com.fh.shop.admin.book.mapper.IBookMapper;
import com.fh.shop.admin.book.po.Book;
import com.fh.shop.admin.common.ServerResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Service("bookService")
public class IBookServiceImpl implements IBookService {

    @Autowired
    private IBookMapper bookMapper;

    @Override
    public ServerResponse addBook(Book book) {
        bookMapper.insert(book);
        return ServerResponse.success();
    }

    @Override
    public ServerResponse deleteBatch(String ids) {
        if (StringUtils.isNotBlank(ids)) {
            List<Long> idList = Arrays.stream(ids.split(",")).map(x -> Long.parseLong(x)).collect(Collectors.toList());
            bookMapper.deleteBatchIds(idList);
        }
        return ServerResponse.success();
    }


}
